home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / doc / gpc / demos / gpc_c_c.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-08  |  2.5 KB  |  90 lines

  1. /*
  2. GPC demo code. C program that includes the Pascal program
  3. gpc_c_pas.pas.
  4.  
  5. Copyright (C) 2000-2001 Free Software Foundation, Inc.
  6.  
  7. Author: Frank Heckenbach <frank@pascal.gnu.de>
  8.  
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License as
  11. published by the Free Software Foundation, version 2.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program; see the file COPYING. If not, write to
  20. the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. Boston, MA 02111-1307, USA.
  22.  
  23. As a special exception, if you incorporate even large parts of the
  24. code of this demo program into another program with substantially
  25. different functionality, this does not cause the other program to
  26. be covered by the GNU General Public License. This exception does
  27. not however invalidate any other reasons why it might be covered
  28. by the GNU General Public License.
  29. */
  30.  
  31. #include <stdio.h>
  32. #include <gpc-in-c.h>
  33.  
  34. /* External declarations we use from the Pascal code */
  35.  
  36. extern int pascal_program_variable;
  37. extern void pascal_program_routine ();
  38.  
  39. extern int pascal_unit_variable;
  40. extern void pascal_unit_routine ();
  41.  
  42. /* C code */
  43.  
  44. int c_variable = 42;
  45.  
  46. void c_routine ()
  47. {
  48.   printf ("C routine called from Pascal code.\n");
  49.   printf ("c_variable is now %i.\n", c_variable);
  50.   fflush (stdout);
  51. }
  52.  
  53. int main (int argc, char **argv, char **envp)
  54. {
  55.   printf ("Starting in the C `main'.\nInitializing the Pascal RTS.\n");
  56.   fflush (stdout); /* So the text really appears now. */
  57.   _p_initialize (argc, argv, envp);
  58.  
  59.   printf ("Calling the Pascal initializers.\n");
  60.   fflush (stdout);
  61.   init_pascal_main_program ();
  62.  
  63.   printf ("Back in C `main'.\n");
  64.   printf ("Incrementing pascal_unit_variable.\n");
  65.   pascal_unit_variable++;
  66.  
  67.   printf ("Calling pascal_unit_routine.\n");
  68.   fflush (stdout);
  69.   pascal_unit_routine ();
  70.  
  71.   printf ("Back in C `main'.\n");
  72.   printf ("c_variable is %i.\n", c_variable);
  73.   printf ("Setting pascal_program_variable to 12345.\n");
  74.   pascal_program_variable = 12345;
  75.  
  76.   printf ("Calling pascal_program_routine.\n");
  77.   fflush (stdout);
  78.   pascal_program_routine ();
  79.  
  80.   printf ("Back in C `main'.\n");
  81.   printf ("Calling the Pascal finalizer.\n");
  82.   fflush (stdout);
  83.   _p_finalize ();
  84.  
  85.   printf ("Done.\n");
  86.   fflush (stdout);
  87.  
  88.   return 0;
  89. }
  90.